package fr.gmdev.mail.mailet.activity;

import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;




public class ActivityLogger {

	private Logger logger = Logger.getLogger(ActivityLogger.class.getName());
	
	public ActivityLogger(String logFolder, int fileSize){
		
		if (logFolder == null ){
			logFolder = "%t/jdc.log";
		}else {
			logFolder = logFolder+"/jdc.log";
		}
		
		try {
			FileHandler handler = new FileHandler(logFolder, fileSize, 5, true);
			
			Formatter f = new Formatter() {
				
				@Override
				public String format(LogRecord record) {
					return record.getMessage() + "\n";
				}
			};
			
			handler.setFormatter(f);//new SimpleFormatter());
			logger.addHandler(handler);
			logger.setUseParentHandlers(false);
		} catch (Exception e) {
			e.printStackTrace();
		} 
	}
	
	

	public void info(String msg) {
		logger.info(msg);
	}

//	public static void main(String[] args) {
//		ActivityLogger logger = new ActivityLogger("/home/gilbert/tmp/test.log" , 1024);
//		for (int i = 0; i < 100; i++) {
//			logger.info("message numero " + i);
//		}
//	}

}
